﻿
using Xacml.Core;
using System.Collections;
using System.Xml;

namespace Xacml.Core.Context
{
  public class EnvironmentElementReadWrite : TargetItemBase
  {
    public EnvironmentElementReadWrite(AttributeCollectionReadWrite attributes, XacmlVersion schemaVersion)
      : base(attributes, schemaVersion)
    {
    }

    public EnvironmentElementReadWrite(XmlReader reader, XacmlVersion schemaVersion)
      : base(reader, "Environment", schemaVersion)
    {
    }

    protected override void AttributeFound(string namespaceName, string attributeName, string attributeValue)
    {
    }

    protected override void NodeFound(XmlReader reader)
    {
    }

    public void WriteDocument(XmlWriter writer)
    {
      writer.WriteStartElement("Environment");
      foreach (AttributeElementReadWrite elementReadWrite1 in (CollectionBase) this.Attributes)
      {
        writer.WriteStartElement("Attribute");
        writer.WriteAttributeString("AttributeId", elementReadWrite1.AttributeId);
        writer.WriteAttributeString("DataType", elementReadWrite1.DataType);
        if (elementReadWrite1.Issuer != null)
          writer.WriteAttributeString("Issuer", elementReadWrite1.Issuer);
        foreach (AttributeValueElementReadWrite elementReadWrite2 in (CollectionBase) elementReadWrite1.AttributeValues)
          writer.WriteElementString("AttributeValue", elementReadWrite2.Value);
        writer.WriteEndElement();
      }
      writer.WriteEndElement();
    }
  }
}
